package com.zyh.work2

object PersonTest {
  def main(args: Array[String]): Unit = {
    val student = new Student("正大",1)
    student.work
    student.eat
    student.sleep
    println(student)
    var peos:Array[Person] = new Array[Person](0)
    peos = peos:+(new Student())
    peos = peos:+(new Worker1())
    peos = peos:+(new StudentLeader())
    println(peos.length)
    var stuls = 0
    for(item<-peos){
      item match {
        case s:StudentLeader => stuls+=1
        case _ => println(item)
      }
    }
    println(s"stuls = ${stuls}")

  }
}
class Person(){
  var name:String = _
  var gender:Boolean = _
  var age:Int = _
  var country:String = _

  def this(name:String,gender:Boolean,age:Int,country:String) = {
    this
    this.name = name
    this.gender = gender
    this.age = age
    this.country = country
  }

  def eat = println("eat()")
  def sleep = println("sleep()")
  def work = println("work()")
}
class Student(var school:String,var id:Int) extends Person{
  def this() = {
    this(null,0)
  }

  override def work: Unit = println("学习")

  override def toString: String = s"$name,$age,$gender,$country,$school,$id"
}
class Worker1(var unit:String,var workYears:Double) extends Person {
  def this() = this(null,0.0)

  override def work: Unit = println("上班")
}
class StudentLeader(var duty:String) extends Student{
  def this() = this(null)

  override def work: Unit = println("开会")
}
